

package l1j.server.server.clientpackets;



import l1j.server.echo.ClientThread;
import l1j.server.server.model.Instance.L1PcInstance;

import java.util.logging.Level;
import java.util.logging.Logger;
/**
 * 處理收到由客戶端傳來登入到伺服器OK的封包
 */
public class C_LoginToServerOK extends ClientBasePacket {

	private static final String C_LOGIN_TO_SERVER_OK = "[C] C_LoginToServerOK";
	private static final Logger _log = Logger.getLogger(C_LoginToServerOK.class.getName());
	@Override
	public String getType() {
		return C_LOGIN_TO_SERVER_OK;
	}

	@Override
	public void start(final byte[] decrypt, final ClientThread client) {
		try {
			// 資料載入
			this.read(decrypt);

			final L1PcInstance pc = client.getActiveChar();
			if (pc == null) {
				return;
			}
			final int type = this.readC();
			final int button = this.readC();

			if (type == 255) { // 全体チャット && Whisper
				if (button == 95 || button == 127) {
					pc.setShowWorldChat(true); // open
					pc.setCanWhisper(true); // open
				} else if (button == 91 || button == 123) {
					pc.setShowWorldChat(true); // open
					pc.setCanWhisper(false); // close
				} else if (button == 94 || button == 126) {
					pc.setShowWorldChat(false); // close
					pc.setCanWhisper(true); // open
				} else if (button == 90 || button == 122) {
					pc.setShowWorldChat(false); // close
					pc.setCanWhisper(false); // close
				}
			} else if (type == 0) { // 全体チャット
				if (button == 0) { // close
					pc.setShowWorldChat(false);
				} else if (button == 1) { // open
					pc.setShowWorldChat(true);
				}
			} else if (type == 2) { // Whisper
				if (button == 0) { // close
					pc.setCanWhisper(false);
				} else if (button == 1) { // open
					pc.setCanWhisper(true);
				}
			} else if (type == 6) { // 商売チャット
				if (button == 0) { // close
					pc.setShowTradeChat(false);
				} else if (button == 1) { // open
					pc.setShowTradeChat(true);
				}
			}
		} catch (final Exception e) {
			_log.log(Level.SEVERE, e.getLocalizedMessage(), e);

		} finally {
			this.over();
		}
	}
}
